package com.li.springbootproject.controller.thread;

import org.slf4j.Logger;

import java.util.concurrent.CountDownLatch;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * @Description：
 * @Author：LiDong
 * @Create：2020/11/11
 * @Version：1.0.0
 */
public class ThreadTask implements Runnable {

    private static final Logger logger= getLogger(ThreadTask.class);


    private final CountDownLatch countDownLatch;

    public ThreadTask(CountDownLatch countDownLatch) {
        this.countDownLatch=countDownLatch;
    }

    @Override
    public void run() {
        try {
            doSomething(countDownLatch);
        } catch (InterruptedException e) {
            e.printStackTrace();
            Thread.currentThread().interrupt();
        }finally {
            String format = String.format("--------线程--------%d---%s", Thread.currentThread().getId(), Thread.currentThread().getName());
            logger.info(format);

        }
    }

    private void doSomething(CountDownLatch countDownLatch) throws InterruptedException {
            logger.info("任务运行");
            Thread.sleep(3000);
        countDownLatch.countDown();
    }
}
